# aem.two_d.transient.unit_step_area_sink --
#
# Copyright (c) 2000, V.Kelson and M.Bakker
#           (c) 2001, Willem Jan Zaadnoordijk

from types import *
from misc.fun_sa import sap1, saq1

import geometry
XY = geometry.XY

import base

import aem.container
RowList = aem.container.RowList
ColumnList = aem.container.ColumnList

class UnitStepAreaSink(base.Element):
	'''Class for transient AreaSink step to be used as child of transient AreaSink

	Python call: UnitStepAreaSink(t,parent)

	Attributes:

	  - time:  start time
	  - parent: parent of the element (inherited from Element)
	  - parameters: dummy ColumnList [1] so that the contribution functions
	                                     do not need to be overloaded

	Overloaded functions from Element: __init__,
	   potentialInfluence, dischargeInfluence, extractionInfluence
	'''

	def __init__(self,t,parent):
		'''Constructor'''
		self.t = t
		base.Element.__init__(self,parent)
		self.parameters=ColumnList([1])

	def __repr__(self):
		# Parent not yet included
		return 'UnitStepAreaSink(t=' + str(self.t) + ')'

	def potentialInfluence(self,xy,t):
		if t > self.t:
			tt = t-self.t
			return RowList( [ sap1(self.parent.vertices,xy,tt,1/self.parent.alpha) ] )
		else:
			return RowList( [0] )

	def dischargeInfluence(self,xy,t):
		if t > self.t:
			tt=t-self.t
			return RowList( [ saq1(self.parent.vertices,xy,tt,1/self.parent.alpha) ] )
		else:
			return RowList( [XY(0.0,0.0)] )

	def extractionInfluence(self,t):
		if t > self.t:
			return RowList( [self.parent.area()] )
		else:
			return RowList( [0] )
